package com.larly.model.vo;

import com.larly.model.domain.NoteVersions;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 记录笔记的历史编辑版本，note_id用于关联笔记但无强制外键约束
 *
 * @TableName note_versions
 */

@Data
public class NoteVersionsVO implements Serializable {
    /**
     * 版本记录ID，自增主键
     */
    private Integer id;

    /**
     * 关联的笔记ID（关联notes表的id）
     */
    private Integer noteId;

    /**
     * 该版本的笔记标题
     */
    private String title;

    /**
     * 该版本的笔记正文
     */
    private String content;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 该版本的创建时间（编辑保存时）
     */
    private Date createdAt;


    private static final long serialVersionUID = 1L;

    /**
     * 实体转换成VO
     *
     * @param noteVersions
     * @return
     */
    public static NoteVersionsVO toVO(NoteVersions noteVersions) {
        NoteVersionsVO noteVersionsVo = new NoteVersionsVO();
        BeanUtils.copyProperties(noteVersions, noteVersionsVo);
        return noteVersionsVo;
    }

    /**
     * VO转换成实体
     *
     * @param noteVersionsVo
     * @return
     */
    public static NoteVersions toEntity(NoteVersionsVO noteVersionsVo) {
        NoteVersions noteVersions = new NoteVersions();
        BeanUtils.copyProperties(noteVersionsVo, noteVersions);
        return noteVersions;
    }
}